---
layout: m1x_soap
title: Downloadable Link Add
---

<h3><a name="product_downloadable_link.add-Module%3AComplexProductAPI"></a>Module: Complex Product API</h3>


<h4><a name="product_downloadable_link.add-Resource%3Aproductdownloadablelink"></a>Resource: product_downloadable_link</h4>


<h5><a name="product_downloadable_link.add-Method%3A"></a>Method:</h5>

<ul>
	<li>product_downloadable_link.add (SOAP V1)</li>
	<li>catalogProductDownloadableLinkAdd (SOAP V2)</li>
</ul>


<p>Allows you to add a new link to a downloadable product.</p>

<p><b>Arguments</b>:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> string </td>
<td> sessionId </td>
<td> Session ID </td>
</tr>
<tr>
<td> string </td>
<td> productId <br class="atl-forced-newline" /> </td>
<td> Product ID </td>
</tr>
<tr>
<td> array </td>
<td> resource <br class="atl-forced-newline" /> </td>
<td> Array of catalogProductDownloadableLinkAddEntity </td>
</tr>
<tr>
<td> string </td>
<td> resourceType <br class="atl-forced-newline" /> </td>
<td> Resource type. Can have one of the following values: "sample" or "link". </td>
</tr>
<tr>
<td> string </td>
<td> store <br class="atl-forced-newline" /> </td>
<td> Store view ID or code (optional) </td>
</tr>
<tr>
<td> string </td>
<td> identifierType <br class="atl-forced-newline" /> </td>
<td> Type of the product identifier. Can have one of the following values: "sku" or "id". </td>
</tr>
</tbody></table>


<p><b>Return</b>:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> int </td>
<td> result </td>
<td> Result of adding a link to the downloadable product </td>
</tr>
</tbody></table>


<p>The <b>catalogProductDownloadableLinkAddEntity</b> content is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> string </td>
<td> title <br class="atl-forced-newline" /> </td>
<td> Link title </td>
</tr>
<tr>
<td> string </td>
<td> price <br class="atl-forced-newline" /> </td>
<td> Custom option value row price </td>
</tr>
<tr>
<td> int </td>
<td> is_unlimited <br class="atl-forced-newline" /> </td>
<td> Defines whether the number of downloads is unlimited </td>
</tr>
<tr>
<td> int </td>
<td> number_of_downloads <br class="atl-forced-newline" /> </td>
<td> Maximum number of possible downloads </td>
</tr>
<tr>
<td> int </td>
<td> is_shareable <br class="atl-forced-newline" /> </td>
<td> Defines whether the link is shareable </td>
</tr>
<tr>
<td> array </td>
<td> sample <br class="atl-forced-newline" /> </td>
<td> Array of catalogProductDownloadableLinkAddSampleEntity </td>
</tr>
<tr>
<td> string </td>
<td> type <br class="atl-forced-newline" /> </td>
<td> Type of the data source. Can have one of the following values: "file" or "url" </td>
</tr>
<tr>
<td> array </td>
<td> file <br class="atl-forced-newline" /> </td>
<td> Array of catalogProductDownloadableLinkFileEntity </td>
</tr>
<tr>
<td> string </td>
<td> link_url <br class="atl-forced-newline" /> </td>
<td> Link URL address </td>
</tr>
<tr>
<td> string </td>
<td> sample_url <br class="atl-forced-newline" /> </td>
<td> Sample URL address </td>
</tr>
<tr>
<td> int </td>
<td> sort_order <br class="atl-forced-newline" /> </td>
<td> Link sort order </td>
</tr>
</tbody></table>





<p>The <b>catalogProductDownloadableLinkAddSampleEntity</b> content is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> string </td>
<td> type </td>
<td> Type of the data source. Can have one of the following values: "file" or "url"&nbsp; <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> array </td>
<td> file <br class="atl-forced-newline" /> </td>
<td> Array of catalogProductDownloadableLinkFileEntity </td>
</tr>
<tr>
<td> string </td>
<td> url <br class="atl-forced-newline" /> </td>
<td> URL to upload </td>
</tr>
</tbody></table>


<p>The <b>catalogProductDownloadableLinkFileEntity</b> content is as follows:</p>

<table><tbody>
<tr>
<th> Type </th>
<th> Name </th>
<th> Description </th>
</tr>
<tr>
<td> string </td>
<td> name <br class="atl-forced-newline" /> </td>
<td> File name </td>
</tr>
<tr>
<td> string </td>
<td> base64_content <br class="atl-forced-newline" /> </td>
<td> BASE64 encoded file <br class="atl-forced-newline" /> </td>
</tr>
</tbody></table>

<p><b>Faults</b>:</p>

<table><tbody>
<tr>
<th> Fault Code </th>
<th> Fault Message </th>
</tr>
<tr>
<td> 414 </td>
<td> Unable to save action. Details in error message. <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td> 415 </td>
<td> Validation error has occurred. <br class="atl-forced-newline" /> </td>
</tr>
</tbody></table>


<h4><a name="product_downloadable_link.add-Examples"></a>Examples</h4>

<h5><a name="product_downloadable_link.add-RequestExampleSOAPV1"></a>Request Example SOAP V1</h5>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div>
		<pre class="theme: Default; brush: php; gutter: false">$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy-&gt;login('apiUser', 'apiKey');
$filesPath = '/var/www/ws/tests/WebService/etc/Modules/Downloadable/Product/Link';
$downloadableProductId = 'downloadable_demo_product';

$items = array(
    'small' =&gt; array(
        'link' =&gt; array(
            'title' =&gt; 'Test file',
            'price' =&gt; '123',
            'is_unlimited' =&gt; '1',
            'number_of_downloads' =&gt; '111',
            'is_shareable' =&gt; '0',
            'sample' =&gt; array(
                'type' =&gt; 'file',
                'file' =&gt;
                array(
                    'filename' =&gt; 'files/test.txt',
                ),
                'url' =&gt; 'http://www.magentocommerce.com/img/logo.gif',
            ),
            'type' =&gt; 'file',
            'file' =&gt;
            array(
                'filename' =&gt; 'files/test.txt',
            ),
            'link_url' =&gt; 'http://www.magentocommerce.com/img/logo.gif',
        ),
        'sample' =&gt; array(
            'title' =&gt; 'Test sample file',
            'type' =&gt; 'file',
            'file' =&gt; array(
                'filename' =&gt; 'files/image.jpg',
            ),
            'sample_url' =&gt; 'http://www.magentocommerce.com/img/logo.gif',
            'sort_order' =&gt; '3',
        )
    ),
    'big' =&gt; array(
        'link' =&gt; array(
            'title' =&gt; 'Test url',
            'price' =&gt; '123',
            'is_unlimited' =&gt; '0',
            'number_of_downloads' =&gt; '111',
            'is_shareable' =&gt; '1',
            'sample' =&gt; array(
                'type' =&gt; 'url',
                'file' =&gt; array(
                    'filename' =&gt; 'files/book.pdf',
                ),
                'url' =&gt; 'http://www.magentocommerce.com/img/logo.gif',
            ),
            'type' =&gt; 'url',
            'file' =&gt; array(
                'filename' =&gt; 'files/song.mp3',
            ),
            'link_url' =&gt; 'http://www.magentocommerce.com/img/logo.gif',
        ),
        'sample' =&gt; array(
            'title' =&gt; 'Test sample url',
            'type' =&gt; 'url',
            'file' =&gt; array(
                'filename' =&gt; 'files/image.jpg',
            ),
            'sample_url' =&gt; 'http://www.magentocommerce.com/img/logo.gif',
            'sort_order' =&gt; '3',
        )
    )
);

$result = true;
foreach ($items as $item) {
    foreach ($item as $key =&gt; $value) {
        if ($value['type'] == 'file') {
            $filePath = $filesPath . '/' . $value['file']['filename'];
            $value['file'] = array('name' =&gt; str_replace('/', '_', $value['file']['filename']), 'base64_content' =&gt; base64_encode(file_get_contents($filePath)), 'type' =&gt; $value['type']);
        }
        if ($value['sample']['type'] == 'file') {
            $filePath = $filesPath . '/' . $value['sample']['file']['filename'];
            $value['sample']['file'] = array('name' =&gt; str_replace('/', '_', $value['sample']['file']['filename']), 'base64_content' =&gt; base64_encode(file_get_contents($filePath)));
        }
        if (!$proxy-&gt;call(
            $sessionId,
            'product_downloadable_link.add',
            array($downloadableProductId, $value, $key)
        )
        ) {
            $result = false;
        }
    }
}</pre>
		</div>
</div></div>



<h5><a name="product_downloadable_link.add-RequestExampleSOAPV2%28WSIComplianceMode%29"></a>Request Example SOAP V2 (WS-I Compliance Mode)</h5>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div>
		<pre class="theme: Default; brush: php; gutter: false">$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

$sessionId = $proxy-&gt;login((object)array('username' =&gt; 'apiUser', 'apiKey' =&gt; 'apiKey'));

$result = $proxy-&gt;catalogProductDownloadableLinkAdd((object)array('sessionId' =&gt; $sessionId-&gt;result, 'productId' =&gt; '3', 'resourceType' =&gt; 'link', 'resource' =&gt; ((object)array(
'title' =&gt; 'link',
'price' =&gt; '10.99',
'sample' =&gt; array(
'type' =&gt; 'url',
'url' =&gt; 'http://sometesturl.com')
))));

var_dump($result-&gt;result);</pre>
		</div>
</div></div>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div>
		<pre class="theme: Default; brush: php; gutter: false">$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

$sessionId = $proxy-&gt;login((object)array('username' =&gt; 'apiUser', 'apiKey' =&gt; 'apiKey'));

$result = $proxy-&gt;catalogProductDownloadableLinkAdd((object)array('sessionId' =&gt; $sessionId-&gt;result, 'productId' =&gt; '3', 'resourceType' =&gt; 'link', 'resource' =&gt; ((object)array(
'title' =&gt; 'link_2',
'price' =&gt; '11.99',
'type' =&gt; 'file',
'file' =&gt; array(
'name' =&gt; 'file_test',
'base64_content' =&gt; '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAAXABcDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDLooor8XP4DCiiigAooooAKKKKAP/Z'
)
))));

var_dump($result-&gt;result);</pre>
		</div>
</div></div>


